package com.baosight.risk.web.xtzy;

import java.util.List;

import javax.ws.rs.core.MediaType;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baosight.risk.api.xtzy.IXtzyOrgService;
import com.baosight.risk.base.controller.BaseController;
import com.baosight.risk.common.annotation.Log;
import com.baosight.risk.common.enums.BusinessType;
import com.baosight.risk.common.result.AjaxResult;
import com.baosight.risk.service.xtzy.entity.XtzyOrg;
import com.baosight.risk.service.xtzy.vo.XtzyOrgVO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * 
 * @author zzw
 *
 */
@Slf4j
@RestController
@RequestMapping("/xtzy/org")
@Api(value = "职能机构信息", description = "职能机构信息", produces = MediaType.APPLICATION_JSON)
public class XtzyOrgController extends BaseController {
    @Autowired
    private IXtzyOrgService orgService;

    /**
     * 查询职能机构信息（全部数据）
     *
     * @param org
     * @return
     */
    @PostMapping("allList")
    @ApiOperation("查询职能机构信息")
    public AjaxResult allList(@RequestBody XtzyOrg org) {
        log.info("查询职能机构信息：" + org.toString());

        List<XtzyOrgVO> result = orgService.selectAllOrg(org);

        return getResultPage(result);
    }
    
    /**
     * 保存职能机构信息
     *
     * @param org
     * @return
     */
    @PostMapping("save")
    @Log(title = "保存职能机构信息")
    @ApiOperation("保存职能机构信息")
    @RequiresPermissions("xtzy:org:save")
    public AjaxResult save(@RequestBody XtzyOrg org) {
        log.info("保存组织机构参数：" + org.toString());
        return toAjax(orgService.save(org));
    }
    
    /**
     * 删除职能机构信息
     * @param id
     * @return
     */
    @GetMapping("delete")
    @Log(title = "删除职能机构信息", businessType = BusinessType.DELETE)
    @RequiresPermissions("xtzy:org:delete")
    @ApiOperation("删除职能机构信息")
    public AjaxResult delete(@RequestParam("id") String id) {
        return toAjax(orgService.deleteSubs(id));
    }

}
